home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1999 May / Cd Pc Users extra 20 mayo 1999.iso / Prog / Inst / Dragtree / FORM1.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-02-14  |  9.1 KB  |  245 lines

  1. VERSION 5.00
  2. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "comctl32.ocx"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   4875
  6.    ClientLeft      =   1785
  7.    ClientTop       =   1455
  8.    ClientWidth     =   5415
  9.    LinkTopic       =   "Form10"
  10.    ScaleHeight     =   4875
  11.    ScaleWidth      =   5415
  12.    Begin ComctlLib.TreeView OrgTree 
  13.       DragIcon        =   "Form1.frx":0000
  14.       Height          =   4335
  15.       Left            =   120
  16.       TabIndex        =   0
  17.       Top             =   480
  18.       Width           =   4575
  19.       _ExtentX        =   8070
  20.       _ExtentY        =   7646
  21.       _Version        =   327682
  22.       LineStyle       =   1
  23.       Style           =   7
  24.       Appearance      =   1
  25.    End
  26.    Begin VB.Image IconImage 
  27.       Height          =   480
  28.       Index           =   3
  29.       Left            =   4800
  30.       Picture         =   "Form1.frx":0152
  31.       Top             =   3480
  32.       Width           =   480
  33.    End
  34.    Begin VB.Image IconImage 
  35.       Height          =   480
  36.       Index           =   2
  37.       Left            =   4800
  38.       Picture         =   "Form1.frx":02A4
  39.       Top             =   3000
  40.       Width           =   480
  41.    End
  42.    Begin VB.Image IconImage 
  43.       Height          =   480
  44.       Index           =   1
  45.       Left            =   4800
  46.       Picture         =   "Form1.frx":03F6
  47.       Top             =   2520
  48.       Width           =   480
  49.    End
  50.    Begin VB.Image TreeImage 
  51.       Height          =   240
  52.       Index           =   6
  53.       Left            =   5160
  54.       Picture         =   "Form1.frx":0548
  55.       Top             =   2160
  56.       Width           =   240
  57.    End
  58.    Begin VB.Image TreeImage 
  59.       Height          =   240
  60.       Index           =   5
  61.       Left            =   5160
  62.       Picture         =   "Form1.frx":064A
  63.       Top             =   1800
  64.       Width           =   240
  65.    End
  66.    Begin VB.Image TreeImage 
  67.       Height          =   240
  68.       Index           =   4
  69.       Left            =   5160
  70.       Picture         =   "Form1.frx":098C
  71.       Top             =   1440
  72.       Width           =   240
  73.    End
  74.    Begin VB.Image TreeImage 
  75.       Height          =   240
  76.       Index           =   3
  77.       Left            =   4800
  78.       Picture         =   "Form1.frx":0CCE
  79.       Top             =   2160
  80.       Width           =   240
  81.    End
  82.    Begin VB.Image TreeImage 
  83.       Height          =   240
  84.       Index           =   2
  85.       Left            =   4800
  86.       Picture         =   "Form1.frx":0DD0
  87.       Top             =   1800
  88.       Width           =   240
  89.    End
  90.    Begin VB.Image TreeImage 
  91.       Height          =   240
  92.       Index           =   1
  93.       Left            =   4800
  94.       Picture         =   "Form1.frx":1112
  95.       Top             =   1440
  96.       Width           =   240
  97.    End
  98.    Begin ComctlLib.ImageList TreeImages 
  99.       Left            =   4800
  100.       Top             =   720
  101.       _ExtentX        =   1005
  102.       _ExtentY        =   1005
  103.       BackColor       =   -2147483643
  104.       MaskColor       =   12632256
  105.       _Version        =   327682
  106.    End
  107. Attribute VB_Name = "Form1"
  108. Attribute VB_GlobalNameSpace = False
  109. Attribute VB_Creatable = False
  110. Attribute VB_PredeclaredId = True
  111. Attribute VB_Exposed = False
  112. Option Explicit
  113. Private Enum ObjectType
  114.     otNone = 0
  115.     otFactory = 1
  116.     otGroup = 2
  117.     otPerson = 3
  118.     otFactory2 = 4
  119.     otGroup2 = 5
  120.     otPerson2 = 6
  121. End Enum
  122. Private SourceNode As Object
  123. Private SourceType As ObjectType
  124. Private TargetNode As Object
  125. ' ***********************************************
  126. ' Return the node's object type.
  127. ' ***********************************************
  128. Private Function NodeType(test_node As Node) As ObjectType
  129.     Select Case Left$(test_node.Key, 1)
  130.         Case "f"
  131.             NodeType = otFactory
  132.         Case "g"
  133.             NodeType = otGroup
  134.         Case "p"
  135.             NodeType = otPerson
  136.     End Select
  137. End Function
  138. ' ***********************************************
  139. ' Prepare the ImageList and TreeView controls.
  140. ' ***********************************************
  141. Private Sub Form_Load()
  142. Dim i As Integer
  143. Dim factory As Node
  144. Dim group As Node
  145. Dim person As Node
  146.     ' Load pictures into the ImageList.
  147.     For i = 1 To 6
  148.         TreeImages.ListImages.Add , , TreeImage(i).Picture
  149.     Next i
  150.     ' Attach the TreeView to the ImageList.
  151.     OrgTree.ImageList = TreeImages
  152.     ' Create some nodes.
  153.     Set factory = OrgTree.Nodes.Add(, , "f R & D", "R & D", otFactory, otFactory2)
  154.     Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Engineering", "Engineering", otGroup, otGroup2)
  155.     Set person = OrgTree.Nodes.Add(group, tvwChild, "p Cameron, Charlie", "Cameron, Charlie", otPerson, otPerson2)
  156.     Set person = OrgTree.Nodes.Add(group, tvwChild, "p Davos, Debbie", "Davos, Debbie", otPerson, otPerson2)
  157.     person.EnsureVisible
  158.     Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Test", "Test", otGroup, otGroup2)
  159.     Set person = OrgTree.Nodes.Add(group, tvwChild, "p Able, Andy", "Andy, Able", otPerson, otPerson2)
  160.     Set person = OrgTree.Nodes.Add(group, tvwChild, "p Baker, Betty", "Baker, Betty", otPerson, otPerson2)
  161.     person.EnsureVisible
  162.     Set factory = OrgTree.Nodes.Add(, , "f Sales & Support", "Sales & Support", otFactory, otFactory2)
  163.     Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Showroom Sales", "Showroom Sales", otGroup, otGroup2)
  164.     Set person = OrgTree.Nodes.Add(group, tvwChild, "p Gaines, Gina", "Gaines, Gina", otPerson, otPerson2)
  165.     person.EnsureVisible
  166.     Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Field Service", "Field Service", otGroup, otGroup2)
  167.     Set person = OrgTree.Nodes.Add(group, tvwChild, "p Helms, Harry", "Helms, Harry", otPerson, otPerson2)
  168.     Set person = OrgTree.Nodes.Add(group, tvwChild, "p Ives, Irma", "Ives, Irma", otPerson, otPerson2)
  169.     Set person = OrgTree.Nodes.Add(group, tvwChild, "p Jackson, Josh", "Jackson, Josh", otPerson, otPerson2)
  170.     person.EnsureVisible
  171.     Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Customer Support", "Customer Support", otGroup, otGroup2)
  172.     Set person = OrgTree.Nodes.Add(group, tvwChild, "p Klug, Karl", "Klug, Karl", otPerson, otPerson2)
  173.     Set person = OrgTree.Nodes.Add(group, tvwChild, "p Landau, Linda", "Landau, Linda", otPerson, otPerson2)
  174.     person.EnsureVisible
  175. End Sub
  176. ' ***********************************************
  177. ' Make the TreeView as large as possible.
  178. ' ***********************************************
  179. Private Sub Form_Resize()
  180.     OrgTree.Move 0, 0, ScaleWidth, ScaleHeight
  181. End Sub
  182. ' ***********************************************
  183. ' Save the node pressed so we can drag it later.
  184. ' ***********************************************
  185. Private Sub OrgTree_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  186.     Set SourceNode = OrgTree.HitTest(x, y)
  187. End Sub
  188. ' ***********************************************
  189. ' Start a drag if one is not in progress.
  190. ' ***********************************************
  191. Private Sub OrgTree_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  192.     If Button = vbLeftButton Then
  193.         ' Start a new drag. Note that we do not get
  194.         ' other MouseMove events while the drag is
  195.         ' in progress.
  196.         
  197.         ' See what node we are dragging.
  198.         SourceType = NodeType(SourceNode)
  199.         ' Select this node. When no node is highlighted,
  200.         ' this node will be displayed as selected. That
  201.         ' shows where it will land if dropped.
  202.         Set OrgTree.SelectedItem = SourceNode
  203.         ' Set the drag icon for this source.
  204.         OrgTree.DragIcon = IconImage(SourceType)
  205.         OrgTree.Drag vbBeginDrag
  206.     End If
  207. End Sub
  208. ' ***********************************************
  209. ' The user is dropping. See if the drop is valid.
  210. ' ***********************************************
  211. Private Sub OrgTree_DragDrop(Source As Control, x As Single, y As Single)
  212.     If Not (OrgTree.DropHighlight Is Nothing) Then
  213.         ' It's a valid drop. Set source node's
  214.         ' parent to be the target node.
  215.         Set SourceNode.Parent = OrgTree.DropHighlight
  216.         Set OrgTree.DropHighlight = Nothing
  217.     End If
  218.     Set SourceNode = Nothing
  219.     SourceType = otNone
  220. End Sub
  221. ' ***********************************************
  222. ' The mouse is being dragged over the control.
  223. ' Highlight the appropriate node.
  224. ' ***********************************************
  225. Private Sub OrgTree_DragOver(Source As Control, x As Single, y As Single, State As Integer)
  226. Dim target As Node
  227. Dim highlight As Boolean
  228.     ' See what node we're above.
  229.     Set target = OrgTree.HitTest(x, y)
  230.     ' If it's the same as last time, do nothing.
  231.     If target Is TargetNode Then Exit Sub
  232.     Set TargetNode = target
  233.     highlight = False
  234.     If Not (TargetNode Is Nothing) Then
  235.         ' See what kind of node were above.
  236.         If NodeType(TargetNode) + 1 = SourceType Then _
  237.             highlight = True
  238.     End If
  239.     If highlight Then
  240.         Set OrgTree.DropHighlight = TargetNode
  241.     Else
  242.         Set OrgTree.DropHighlight = Nothing
  243.     End If
  244. End Sub
  245.